package com.szp.spCloud.common.service.impl;

import com.szp.spCloud.common.pojo.Token;
import com.szp.spCloud.common.service.TokenValidateService;
import com.szp.spCloud.user.dao.TokenRepository;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;

import java.util.Optional;
@Service
public class TokenValidateServiceImpl implements TokenValidateService {
    @Autowired
    TokenRepository tokenRepository;
    @Override
    public String info(String tokenStr) {
        Token token = new Token();
        token.setToken(tokenStr);
        Optional<Token> res = tokenRepository.findOne(Example.of(token));
        if(res.isPresent()){
            return res.get().getEmail();
        }
        return null;
    }
}
